<?php
require('functions/page_load.php');
require("fckeditor/fckeditor.php");

$content_nav = true;

if($_SERVER['REQUEST_METHOD'] == 'POST'){

$article_date = date("Y-m-d", strtotime(str_replace("/", "-", $_POST['article_date'])));

$sql = "UPDATE blog SET article_content = '".mysql_real_escape_string(stripslashes($_POST['category_content']))."', article_url = '".mysql_real_escape_string($_POST['article_url'])."', article_title = '".mysql_real_escape_string($_POST['article_title'])."', article_date = '".$article_date."' WHERE id = '".$_GET['id']."'";
$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());

$results = '<div class="success_result">Article updated successfully!</div>';

}

$results = ($_GET['new'] == 'true') ? '<span class="success_result" style="margin-bottom: 10px;">Article successfully created.</span>' : $results ;

$sql = "SELECT article_content, article_url, article_title, article_date FROM blog WHERE id = '".$_GET['id']."'";
$query = mysql_query( $sql ) or die ("Error in query: $sql. " . mysql_error());
$rs = mysql_fetch_assoc($query);

require('includes/header.php');
?>

<div class="side_container">
<h2 class="container_header">Navigation</h2>

<ul>
<li><a href="content.php">Pages</a></li>
<li><a href="blog.php">Blog</a></li>
<li><a href="directory.php">Directory</a></li>
<li><a href="faqs.php">FAQs</a></li>
</ul>

</div>

<div class="main_container_wrapper">

	<div class="main_container">
	<h2 class="container_header">Edit Page - <?php echo $rs['name']; ?></h2>
	
	<?php echo $results; ?>
	
	<form method="post" action="">

	
	<div class="form_row_wrapper">
	<div class="form_row_left"><label for="article_title">Article title*:</label></div>
	<div class="form_row_right"><input type="text" name="article_title" id="name" value="<?php echo $rs['article_title']; ?>" onkeyup="buildUrl();" onkeydown="buildUrl();" /></div>
	</div>

	<div class="form_row_wrapper">
	<div class="form_row_left"><label for="article_url">Article URL*:</label></div>
	<div class="form_row_right"><input type="text" name="article_url" id="url" value="<?php echo $rs['article_url']; ?>" /> <span>This must be a unique and web-safe name for the page.</span></div>
	</div>
	
	<div class="form_row_wrapper">
	<div class="form_row_left"><label for="article_date">Article date:</label></div>
	<div class="form_row_right"><input type="text" name="article_date" id="article_date" value="<?php echo (isset($rs['article_date'])) ? date("d/m/Y", strtotime($rs['article_date'])) : date("d/m/Y"); ?>" style="width: 80px;" /></div>
	</div>
	
	<script type="text/javascript">
	$(function() {
		$("#article_date").datepicker({ dateFormat: 'dd/mm/yy', setDate: '<?php echo (isset($rs['article_date'])) ? date("d/m/Y", strtotime($rs['article_date'])) : date("d/m/Y"); ?>' });
	});
	</script>

	<div class="form_row_wrapper">
	<div class="form_row_left"><label>Content:</label></div>
	<div class="form_row_right">
	<?php
	$oFCKeditor = new FCKeditor('category_content');
	$oFCKeditor->Height = '400';
	$oFCKeditor->BasePath = '/admin/fckeditor/';
	$oFCKeditor->Value = $rs['article_content'];
	$oFCKeditor->Create();
	?>
	</div>
	</div>
	
	<div class="form_row_wrapper">
	<div class="form_row_left">&nbsp;</div>
	<div class="form_row_right"><input type="image" src="images/save_button.png" alt="Save" /></div>
	</div>
	
	</form>

	</div>

</div>
	
<?php
	require('includes/footer.php');
?>